

package com.thxrinfo.stop.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import com.thxrinfo.stop.api.entity.RegionLotRoad;
import com.thxrinfo.stop.service.RegionLotRoadService;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;


/**
 * 路边车场车位表
 *
 * @author ct
 * @date 2023-02-08 13:35:23
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/regionlotroad" )
@Tag(name = "路边车场车位表管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class RegionLotRoadController {

    private final  RegionLotRoadService regionLotRoadService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param regionLotRoad 路边车场车位表
     * @return
     */
    @Operation(summary = "分页查询", description = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('stop_regionlotroad_get')" )
    public R getRegionLotRoadPage(Page page, RegionLotRoad regionLotRoad) {
        return R.ok(regionLotRoadService.getList(page, regionLotRoad));
    }

	@Operation(summary = "查询所有车位", description = "查询所有车位")
	@GetMapping("/all" )
	@PreAuthorize("@pms.hasPermission('stop_regionlotroad_get')" )
	public R getAllRoadLot(@RequestParam(value = "regionId", defaultValue = "-1") Long regionId) {
		QueryWrapper<RegionLotRoad> regionLotRoadQueryWrapper = new QueryWrapper<>();
		regionLotRoadQueryWrapper.eq(regionId != null, "region_id", regionId)
				.orderBy(true, false, "update_time");
		return R.ok(regionLotRoadService.list(regionLotRoadQueryWrapper));
	}

    /**
     * 通过id查询路边车场车位表
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询", description = "通过id查询")
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('stop_regionlotroad_get')" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(regionLotRoadService.getById(id));
    }

    /**
     * 新增路边车场车位表
     * @param regionLotRoad 路边车场车位表
     * @return R
     */
    @Operation(summary = "新增路边车场车位表", description = "新增路边车场车位表")
    @SysLog("新增路边车场车位表" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('stop_regionlotroad_add')" )
    public R save(@RequestBody RegionLotRoad regionLotRoad) {
        return R.ok(regionLotRoadService.save(regionLotRoad));
    }

    /**
     * 修改路边车场车位表
     * @param regionLotRoad 路边车场车位表
     * @return R
     */
    @Operation(summary = "修改路边车场车位表", description = "修改路边车场车位表")
    @SysLog("修改路边车场车位表" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('stop_regionlotroad_edit')" )
    public R updateById(@RequestBody RegionLotRoad regionLotRoad) {
        return R.ok(regionLotRoadService.updateById(regionLotRoad));
    }

    /**
     * 通过id删除路边车场车位表
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id删除路边车场车位表", description = "通过id删除路边车场车位表")
    @SysLog("通过id删除路边车场车位表" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('stop_regionlotroad_del')" )
    public R removeById(@PathVariable Long id) {
        return R.ok(regionLotRoadService.removeById(id));
    }

}
